﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Compilation;

namespace System.Web.ScriptBuilder
{
	public class ScriptLinkerFactory : IHttpHandlerFactory
	{
		public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string path)
		{
			return this.GetHandlerHelper(context, requestType, virtualPath, path);
		}

		private IHttpHandler GetHandlerHelper(HttpContext context, string requestType, string virtualPath, string physicalPath)
		{
			var composer = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(ScriptLinkerBase)) as ScriptLinkerBase;
			if (composer == null)
				return null;

			return composer;
		}

		public virtual void ReleaseHandler(IHttpHandler handler)
		{
		}
	}
}